package chapter04;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class TestDeadLock {
    private static final Object LOCKA=new Object();
    private static final Object LOCKB=new Object();

    public static void main(String[] args) {
        new Thread(()->{
            synchronized (LOCKA){
                log.debug("t1 get lockA");
                try {
                    TimeUnit.MILLISECONDS.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (LOCKB){
                    log.debug("t1 get lockB");
                }
            }
        },"t1").start();

        new Thread(()->{
            synchronized (LOCKB){
                log.debug("t2 get lockB");
                try {
                    TimeUnit.MILLISECONDS.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (LOCKA){
                    log.debug("t2 get lockA");
                }
            }
        },"t2").start();

    }
}
